<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div id="dialog-message_class">
	<div style="height:400px;overflow:auto;">
		<ul id="treeDemo4" class="ztree"></ul>
	</div>
	<div>
		<hr>
		 当前教学计划适用标签：<div id="learnPlant_andLabletextButton" class="btn btn-info"></div>
	</div>
</div>
<script type="text/javascript">
(function(){
			var arr = new Array();
			function zTreeOnClick(event, treeId, treeNode){
				var arr1 = new Array();
				var b =false;
				//两个数组是用来，如果有就删除，没有就增加的
				for(var i=0;i<arr.length;i++){
					if(arr[i].table_id == treeNode.table_id){
						b=true;
					}else{
						arr1.push(arr[i]);
					}
				}
				if(b==true){
					arr =arr1;
				}else{
					 var node = new Object();
					 node.table_id = treeNode.table_id;
					 node.text = treeNode.name;
					 arr.push(node);
				}   
				//显示出来
				
				var vt ="";
				for(var i=0;i<arr.length;i++){
					if(i==arr.length-1){
						vt+='<button class="btn btn-xs btn-inverse" style="margin-top:4px;" name="lablebuton" table_id="'+arr[i].table_id+'">'+arr[i].text+'<i class="icon-remove"></i></button>';
						 
					}else{
						vt+='<button class="btn btn-xs btn-inverse" style="margin-top:4px;" name="lablebuton" table_id="'+arr[i].table_id+'">'+arr[i].text+'<i class="icon-remove"></i></button>&nbsp;';
					}
				}
				$("#learnPlant_andLabletextButton").html(vt);
				$("#learnPlant_addLable_show").html(vt);
				$("button[name=lablebuton]").unbind().click(function(){
					$(this).remove();
				});
			}
	
		var setting = {	
			view: {
				dblClickExpand: false,
				showLine: true,
				selectedMulti: false
			},callback: {
				onClick: zTreeOnClick
			},
			data: { 
			simpleData: {
				enable:true,
				idKey: "lableId",
				pIdKey: "lablePid", 
				rootPId: "0"
			}
		}};
	 
	   function loadTree(){
		    var url ="${pageContext.request.contextPath}/edu/sys_LableAction.do?method=getAllLable";
			 $.ajax({
			   type: "POST",
			   url: url,				
			   dataType:"json",
			   success: function(msg){  
				   $.fn.zTree.init($("#treeDemo4"), setting, msg[0].list);
			   }
			}); 
	 }
	function addLearnPlantLable(contrl){
		$("#learnPlant_addLable").data("arr",arr);
		$(contrl).dialog("destroy" ); 
		$("#learnPlantAdd_ClassWindow").html(""); 
	};
	$(function(){
		loadTree();
	});
	window.dialog_message_lable={};
	window.dialog_message_lable.addLearnPlantLable=addLearnPlantLable;
})();
</script> 